/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.dto.ComplainDto;
import com.excesys.exsecs.om.entity.OmWOrderComplain;
import com.excesys.exsecs.om.service.OmWOrderComplainService;
import com.excesys.exsecs.om.vo.ComplainExcelVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 投诉工单表
 *
 * @author weiyj
 * @date 2023-02-24 13:53:35
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/omwordercomplain")
@Tag(name = "投诉工单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmWOrderComplainController {

	private final OmWOrderComplainService omWOrderComplainService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param omWOrderComplain 投诉
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_get')")
	public R getOmWOrderComplainPage(Page page, OmWOrderComplain omWOrderComplain) {
		return R.ok(omWOrderComplainService.getComplainPage(page, omWOrderComplain));
	}

	/**
	 * 通过id查询投诉
	 * @param cpId id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{cpId}")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_get')")
	public R getById(@PathVariable("cpId") Integer cpId) {
		return R.ok(omWOrderComplainService.getById(cpId));
	}

	/**
	 * 新增投诉
	 * @param omWOrderComplain 投诉
	 * @return R
	 */
	@Operation(summary = "新增投诉", description = "新增投诉")
	@SysLog("新增投诉")
	@PostMapping
	// @PreAuthorize("@pms.hasPermission('om_omwordercomplain_add')" )
	public R save(@RequestBody OmWOrderComplain omWOrderComplain) {
		return R.ok(omWOrderComplainService.saveComplain(omWOrderComplain));
	}

	/**
	 * 修改投诉
	 * @param omWOrderComplain 投诉
	 * @return R
	 */
	@Operation(summary = "修改投诉", description = "修改投诉")
	@SysLog("修改投诉")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_get')")
	public R updateById(@RequestBody OmWOrderComplain omWOrderComplain) {
		return R.ok(omWOrderComplainService.updateById(omWOrderComplain));
	}

	/**
	 * 通过id删除投诉
	 * @param cpId id
	 * @return R
	 */
	@Operation(summary = "通过id删除投诉", description = "通过id删除投诉")
	@SysLog("通过id删除投诉")
	@DeleteMapping("/{cpId}")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_del')")
	public R removeById(@PathVariable Integer cpId) {
		return R.ok(omWOrderComplainService.removeById(cpId));
	}

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param omWOrderComplain 投诉
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/waitPage")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_get')")
	public R getComplainPage(Page page, OmWOrderComplain omWOrderComplain) {
		return R.ok(omWOrderComplainService.getComplainPage(page, omWOrderComplain));
	}

	/**
	 * 投诉操作
	 * @param complainDto 投诉操作
	 * @return R
	 */
	@Operation(summary = "投诉操作", description = "投诉操作")
	@SysLog("投诉操作")
	@PostMapping("/operate")
	// @PreAuthorize("@pms.hasPermission('om_omworder_add')" )
	public R operateOmWOrder(@RequestBody ComplainDto complainDto) {

		return R.ok(omWOrderComplainService.operateComplain(complainDto));
	}

	/**
	 * 删除多个投诉
	 * @param idList 删除多个投诉
	 * @return R
	 */
	@Operation(summary = "删除多个投诉", description = "删除多个投诉")
	@SysLog("删除多个投诉")
	@DeleteMapping("/removeByIds")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_del')")
	public R removeByIds(@RequestBody List<Integer> idList) {
		return R.ok(omWOrderComplainService.removeByIds(idList));
	}

	/**
	 * 导出excel 表格
	 * @param omWOrderComplain 查询条件
	 * @return
	 */
	@ResponseExcel
	@GetMapping("/export")
	@PreAuthorize("@pms.hasPermission('om_omwordercomplain_get')")
	public List<ComplainExcelVO> export(OmWOrderComplain omWOrderComplain) {
		return omWOrderComplainService.getComplainList(omWOrderComplain);
	}

}
